package work.linruchang.oauthclientproject.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import work.linruchang.oauthclientproject.config.interceptor.BasicAuthInterceptor;
import work.linruchang.oauthclientproject.config.interceptor.OauthAuthInterceptor;

/**
 * 自定义Spring配置
 *
 * @author LinRuChang
 * @version 1.0
 * @date 2022/08/04
 * @since 1.8
 **/
@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    OauthAuthInterceptor oauthAuthInterceptor;
    @Autowired
    BasicAuthInterceptor basicAuthInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(oauthAuthInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/js/**","/user-oauth","/user-oauth/login","/user-oauth/callback","/user-oauth/oauth-url","/error","/**/logout/**","/","/index","/user-oauth/oauth-info-admin","/user-oauth/all-token-infos","/user-oauth/basic-logout");

        registry.addInterceptor(basicAuthInterceptor)
                .addPathPatterns("/user-oauth/oauth-info-admin","/user-oauth/all-token-infos","/user-oauth/basic-logout");

    }

}
